package com.kujie.loader.vector;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class ResourceLoaderFactory {

    private final Map<String, ResourceLoader> loaderMap = new ConcurrentHashMap<>();

    public ResourceLoaderFactory() {
        // 注册各种文件类型的处理器
        loaderMap.put("txt", new TextFileLoader());
        loaderMap.put("doc", new DocLoader());
        loaderMap.put("docx", new DocxLoader());
        loaderMap.put("pdf", new PdfFileLoader());
        loaderMap.put("md", new MarkDownFileLoader());
        loaderMap.put("csv", new TextFileLoader());
        loaderMap.put("java", new CodeFileLoader());
        loaderMap.put("js", new CodeFileLoader());
        loaderMap.put("html", new CodeFileLoader());
        loaderMap.put("css", new CodeFileLoader());
        loaderMap.put("xml", new TextFileLoader());
        loaderMap.put("json", new TextFileLoader());
        loaderMap.put("properties", new TextFileLoader());
        loaderMap.put("yml", new TextFileLoader());
        loaderMap.put("yaml", new TextFileLoader());
    }

    public ResourceLoader getLoaderByFileType(String fileType) {
        ResourceLoader loader = loaderMap.get(fileType.toLowerCase());
        return loader != null ? loader : new TextFileLoader(); // 默认使用文本处理器
    }
}
